﻿@using eLoan.Models;
@model LoanNotificationModel

@{
    ViewBag.Title = "Loan Notification";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Loan Notification</h2>
        <ol class="breadcrumb">
            <li>
                Workspace
            </li>
            <li class="active">
                <strong>Loan Notification</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>

@using (Html.BeginForm("RefreshLoanNotification", "Workspace", FormMethod.Post, new { id = "saveForm" }))
{
    <fieldset>

        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h3>@Html.DisplayFor(m => Model.ModemValidation)</h3>
                        </div>
                        <div class="ibox-title">
                            <div class="divSearch">
                                <div class="row">
                                    <div class="col-lg-3">
                                        @Html.LabelFor(m => m.Branches)
                                        @Html.DropDownListFor(m => m.SelectedBranchCode, Model.Branches, new { @id = "ddlBranches", @class = "single-line", @onchange = "GetAgents()" })
                                    </div>
                                    <div class="col-lg-3">
                                        @Html.LabelFor(m => m.Agents)
                                        @Html.DropDownListFor(m => m.SelectedAgentID, Model.Agents, new { @id = "ddlAgents", @class = "single-line" })
                                    </div>
                                    <div class="col-lg-3" style="padding-bottom : 0px !important">
                                        <br />
                                        <button type="submit" id="btnRefresh" class="btn btn-primary" name="command" value="Refresh">Search</button>
                                    </div>
                                    <div class="col-lg-3" style="text-align:right">
                                        <br />
                                        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#confirm-post">Send Notifications</button>
                                        <button type="submit" id="btnSend" class="hidden" name="command" value="SendNotification"></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="ibox-title">
                            <h3>Delayed Loans</h3>
                            @Html.DropDownListFor(m => m.SelectedDelayedNotificationID, Model.Notifications, new { @class = "btn btn-white" })
                         </div>
                        <div class="ibox-content">
                            <table id="tbl" class="table table-bordered table-List">
                                <thead>
                                    <tr>
                                        <th>Borrower</th>
                                        <th>Document No</th>
                                        <th>Outstanding Balance</th>
                                        <th>Receivable</th>
                                        <th>Total Payment</th>
                                        <th>Short / Over</th>
                                        <th>Loan Date</th>
                                        <th>Maturity Date</th>
                                        <th>Payment Type</th>
                                        <th>Penalty Balance</th>
                                        <th>Contact Numbers</th>
                                        <th>Loan Status</th>
                                        <th class="text-left"><input id="chkAllDelayed" type="checkbox" class="checkbox allDelayed" onchange="CheckAll(this, '.delayed')" /></th>
                                    </tr>
                                </thead>
                                <tbody id="tableBody">
                                    @for (var i = 0; i < Model.DelayedLoans.Count(); i++)
                                    {
                                    <tr>
                                        <td>
                                            @Html.HiddenFor(m => m.DelayedLoans[i].BorrowerName)
                                            @Html.ActionLink(Model.DelayedLoans[i].BorrowerName, "LoanJournal", "Loan", null, null, null, new { documentNo = Model.DelayedLoans[i].DocumentNo }, null)
                                        </td>
                                        <td>
                                            @Html.HiddenFor(m => m.DelayedLoans[i].DocumentNo)
                                            @Html.ActionLink(Model.DelayedLoans[i].DocumentNo, "LoanDetails", "Loan", null, null, null, new { documentNo = Model.DelayedLoans[i].DocumentNo }, null)
                                        </td>
                                        <td style="text-align:right">
                                            @Html.ValueFor(m => m.DelayedLoans[i].OutstandingBalance, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.DelayedLoans[i].OutstandingBalance)
                                        </td>
                                        <td style="text-align:right">
                                            @Html.ValueFor(m => m.DelayedLoans[i].Receivable, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.DelayedLoans[i].Receivable)
                                        </td>
                                        <td style="text-align:right">
                                            @Html.ValueFor(m => m.DelayedLoans[i].TotalPayment, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.DelayedLoans[i].TotalPayment)
                                        </td>
                                        <td style="text-align:right">
                                            @Html.ValueFor(m => m.DelayedLoans[i].ShortOver, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.DelayedLoans[i].ShortOver)
                                        </td>
                                        <td>
                                            @Html.ValueFor(m => m.DelayedLoans[i].DocumentDate, "{0:MMM/dd/yyyy}")
                                            @Html.HiddenFor(m => m.DelayedLoans[i].DocumentDate)
                                        </td>
                                        <td>
                                            @Html.ValueFor(m => m.DelayedLoans[i].PaymentEndDate, "{0:MMM/dd/yyyy}")
                                            @Html.HiddenFor(m => m.DelayedLoans[i].PaymentEndDate)
                                        </td>
                                        <td>
                                            @Html.HiddenFor(m => m.DelayedLoans[i].PaymentTypeID)
                                            @Html.HiddenFor(m => m.DelayedLoans[i].PaymentTypeName)
                                            @Html.ValueFor(m => m.DelayedLoans[i].PaymentTypeName)
                                        </td>
                                        <td style="text-align:right">
                                            @Html.ValueFor(m => m.DelayedLoans[i].PenaltyBalance, "{0:#,###,##0.00}")
                                            @Html.HiddenFor(m => m.DelayedLoans[i].PenaltyBalance)
                                        </td>
                                        <td>
                                            @Html.ValueFor(m => m.DelayedLoans[i].ContactNumbers)
                                            @Html.HiddenFor(m => m.DelayedLoans[i].ContactNumbers)
                                        </td>
                                        <td>
                                            @Html.ValueFor(m => m.DelayedLoans[i].LoanStatus)
                                            @Html.HiddenFor(m => m.DelayedLoans[i].LoanStatus)
                                        </td>
                                        <td class="text-left">
                                            @Html.CheckBoxFor(m => m.DelayedLoans[i].IsSelected, new { @class = "delayed" })
                                        </td>
                                    </tr>
                                    }
                                </tbody>
                            </table>
                        </div>

                        <div class="ibox-title">
                            <h3>Delinquent Loans</h3>
                            @Html.DropDownListFor(m => m.SelectedDelingquentNotificationID, Model.Notifications, new { @class = "btn btn-white" })
                        </div>
                        <div class="ibox-content">
                            <table id="tbl" class="table table-bordered table-List">
                                <thead>
                                    <tr>
                                        <th>Borrower</th>
                                        <th>Document No</th>
                                        <th>Outstanding Balance</th>
                                        <th>Receivable</th>
                                        <th>Total Payment</th>
                                        <th>Short / Over</th>
                                        <th>Loan Date</th>
                                        <th>Maturity Date</th>
                                        <th>Payment Type</th>
                                        <th>Penalty Balance</th>
                                        <th>Contact Numbers</th>
                                        <th>Loan Status</th>
                                        <th class="text-left"><input id="chkAllDelinquent" type="checkbox" class="checkbox allDelinquent" onchange="CheckAll(this, '.delinquent')" /></th>
                                    </tr>
                                </thead>
                                <tbody id="tableBody">
                                    @for (var i = 0; i < Model.DelinquentLoans.Count(); i++)
                                    {
                                        <tr>
                                            <td>
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].BorrowerName)
                                                @Html.ActionLink(Model.DelinquentLoans[i].BorrowerName, "LoanJournal", "Loan", null, null, null, new { documentNo = Model.DelinquentLoans[i].DocumentNo }, null)
                                            </td>
                                            <td>
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].DocumentNo)
                                                @Html.ActionLink(Model.DelinquentLoans[i].DocumentNo, "LoanDetails", "Loan", null, null, null, new { documentNo = Model.DelinquentLoans[i].DocumentNo }, null)
                                            </td>
                                            <td style="text-align:right">
                                                @Html.ValueFor(m => m.DelinquentLoans[i].OutstandingBalance, "{0:#,###,##0.00}")
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].OutstandingBalance)
                                            </td>
                                            <td style="text-align:right">
                                                @Html.ValueFor(m => m.DelinquentLoans[i].Receivable, "{0:#,###,##0.00}")
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].Receivable)
                                            </td>
                                            <td style="text-align:right">
                                                @Html.ValueFor(m => m.DelinquentLoans[i].TotalPayment, "{0:#,###,##0.00}")
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].TotalPayment)
                                            </td>
                                            <td style="text-align:right">
                                                @Html.ValueFor(m => m.DelinquentLoans[i].ShortOver, "{0:#,###,##0.00}")
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].ShortOver)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.DelinquentLoans[i].DocumentDate, "{0:MMM/dd/yyyy}")
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].DocumentDate)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.DelinquentLoans[i].PaymentEndDate, "{0:MMM/dd/yyyy}")
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].PaymentEndDate)
                                            </td>
                                            <td>
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].PaymentTypeID)
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].PaymentTypeName)
                                                @Html.ValueFor(m => m.DelinquentLoans[i].PaymentTypeName)
                                            </td>
                                            <td style="text-align:right">
                                                @Html.ValueFor(m => m.DelinquentLoans[i].PenaltyBalance, "{0:#,###,##0.00}")
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].PenaltyBalance)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.DelinquentLoans[i].ContactNumbers)
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].ContactNumbers)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.DelinquentLoans[i].LoanStatus)
                                                @Html.HiddenFor(m => m.DelinquentLoans[i].LoanStatus)
                                            </td>
                                            <td class="text-left">
                                                @Html.CheckBoxFor(m => m.DelinquentLoans[i].IsSelected, new { @class = "delinquent" })
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>

                        <div class="ibox-title">
                            <h3>Loans Candidate for Renewal</h3>
                            @Html.DropDownListFor(m => m.SelectedRenewalNotificationID, Model.Notifications, new { @class = "btn btn-white" })
                        </div>
                        <div class="ibox-content">
                            <table id="tbl" class="table table-bordered table-List">
                                <thead>
                                    <tr>
                                        <th>Borrower</th>
                                        <th>Document No</th>
                                        <th>Loan Date</th>
                                        <th>Maturity Date</th>
                                        <th>Contact Numbers</th>
                                        <th>Loan Status</th>
                                        <th>Remarks</th>
                                        <th class="text-left"><input id="chkAllRenewal" type="checkbox" class="checkbox allRenewal" onchange="CheckAll(this, '.renewal')" /></th>
                                    </tr>
                                </thead>
                                <tbody id="tableBody">
                                    @for (var i = 0; i < Model.LoanForRenewal.Count(); i++)
                                    {
                                        <tr>
                                            <td>
                                                @Html.HiddenFor(m => m.LoanForRenewal[i].BorrowerName)
                                                @Html.ActionLink(Model.LoanForRenewal[i].BorrowerName, "BorrowerLoanHistory", "Borrower", null, null, null, new { borrowerID = Model.LoanForRenewal[i].BorrowerID }, null)
                                            </td>
                                            <td>
                                                @Html.HiddenFor(m => m.LoanForRenewal[i].DocumentNo)
                                                @Html.ActionLink(Model.LoanForRenewal[i].DocumentNo, "LoanDetails", "Loan", null, null, null, new { documentNo = Model.LoanForRenewal[i].DocumentNo }, null)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.LoanForRenewal[i].DocumentDate, "{0:MMM/dd/yyyy}")
                                                @Html.HiddenFor(m => m.LoanForRenewal[i].DocumentDate)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.LoanForRenewal[i].PaymentEndDate, "{0:MMM/dd/yyyy}")
                                                @Html.HiddenFor(m => m.LoanForRenewal[i].PaymentEndDate)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.LoanForRenewal[i].ContactNumbers)
                                                @Html.HiddenFor(m => m.LoanForRenewal[i].ContactNumbers)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.LoanForRenewal[i].LoanStatus)
                                                @Html.HiddenFor(m => m.LoanForRenewal[i].LoanStatus)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.LoanForRenewal[i].Remarks)
                                                @Html.HiddenFor(m => m.LoanForRenewal[i].Remarks)
                                            </td>
                                            <td class="text-left">
                                                @Html.CheckBoxFor(m => m.LoanForRenewal[i].IsSelected, new { @class = "renewal" })
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>

                        <div class="ibox-title">
                            <h3>Loan Prospects</h3>
                            @Html.DropDownListFor(m => m.SelectedProspectNotificationID, Model.Notifications, new { @class = "btn btn-white" })
                        </div>
                        <div class="ibox-content">
                            <table id="tbl" class="table table-bordered table-List">
                                <thead>
                                    <tr>
                                        <th>Prospect</th>
                                        <th>Loan Offer</th>
                                        <th>Address</th>
                                        <th>Contact Numbers</th>
                                        <th>Emaill Addresses</th>
                                        <th class="text-left"><input id="chkAllProspects" type="checkbox" class="checkbox allProspects" onchange="CheckAll(this, '.prospects')" /></th>
                                    </tr>
                                </thead>
                                <tbody id="tableBody">
                                    @for (var i = 0; i < Model.LoanProspects.Count(); i++)
                                    {
                                        <tr>
                                            <td>
                                                @Html.DisplayFor(m => m.LoanProspects[i].ProspectName)
                                                @Html.HiddenFor(m => m.LoanProspects[i].ProspectName)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.LoanProspects[i].LoanOffer, "{0:#,###,##0.00}")
                                                @Html.HiddenFor(m => m.LoanProspects[i].LoanOffer)
                                            </td>
                                            <td>
                                                @Html.DisplayFor(m => m.LoanProspects[i].Address)
                                                @Html.HiddenFor(m => m.LoanProspects[i].Address)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.LoanProspects[i].ContactNumbers)
                                                @Html.HiddenFor(m => m.LoanProspects[i].ContactNumbers)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.LoanProspects[i].EmailAddresses)
                                                @Html.HiddenFor(m => m.LoanProspects[i].EmailAddresses)
                                            </td>
                                            <td class="text-left">
                                                @Html.CheckBoxFor(m => m.LoanProspects[i].IsSelected, new { @class = "prospects" })
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>

                        <div class="modal fade" id="confirm-post" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">

                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                        <h4 class="modal-title" id="myModalLabel">Confirmation</h4>
                                    </div>

                                    <div class="modal-body">
                                        <p>Are you sure you want to send notifications to selected accounts?</p>
                                        <p class="debug-url"></p>
                                    </div>

                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-primary" data-dismiss="modal">No</button>
                                        <button type="button" class="btn btn-primary btn-ok" data-dismiss="modal">Yes</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </fieldset>
}
@section Styles {
@Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
@Styles.Render("~/plugins/dataPickerStyles")
    <style>

    .table-search {
        width: 100%;
        border: none;
    }

        .table-search th {
            width: 250px;
        }

            .table-search th label {
                margin-top: 15px;
                margin-left: 20px;
            }

            .table-search th .span {
                padding-left: 10px;
            }

        .table-search .align-right{
            text-align: right;
        }

            .table-search td select {
                margin-left: 15px !important;
                margin-bottom: 10px !important;
            }

            .table-search td input {
                margin-left: 25px !important;
                margin-bottom: 10px !important;
            }

            .table-search td button {
                margin-right: 15px;
                margin-bottom: 10px !important;
            }

        .table-search td .btnSearch {
            margin-bottom: 0px;
            margin-left: 40px !important;
        }

    .divSearch {
        margin-bottom: 5px;
        padding:15px;
        background-color: #F5F5F6;
        border: 1px solid #EBEBEB;
    }

</style>

}

@section Scripts {
@Scripts.Render("~/plugins/dataTables")
@Scripts.Render("~/plugins/dataPicker")

<script type="text/javascript">

    $(document).ready(function () {

        $('.table-List').dataTable({
            ordering: true,
            searching: false,
            paging: false
        });

        $(window).keydown(function (event) {
            if (event.keyCode == 13) {
                Refresh();
                return false;
            }
        });

        $('#confirm-post').on('click', '.btn-ok', function (e) {
            document.getElementById('btnSend').click();
        });

    });

    function Refresh() {
        document.getElementById('btnRefresh').click();
    }

    function CheckAll(me, css)
    {
        var bln = $(me).is(':checked');

        $(css).each(function () {
            $(this).prop('checked', bln);
        });
        
    }

    function GetAgents()
    {
        var val = $('#ddlBranches').val();
        var subItems = "";

        $.getJSON("@Url.Action("GetAgents","Borrower")", { branchCode: val },
    function (data) {

        $.each(data, function (index, item) {

            subItems += "<option value='" + $.trim(item.Value) + "'>" + $.trim(item.Text) + "</option>"

        });

        $("#ddlAgents").html(subItems)
    });
    }

</script>

}
